/**============================================================================
 *
 * Author: luo1o1o1o 
 *
 * Last modified: 2021-07-23 15:09
 *
 * Description: 首页 controller
 *
 ============================================================================**/

const xss = require('xss')
const { createBlog } = require('../services/blog')
const { SuccessModel, ErrorModel } = require('../model/ResModel')
const { createBlogFailInfo } = require('../model/ErrorInfo')

/**
 * @Author: luo1o1o1o
 * @Date: 2021-07-23 15:10
 * @desc: 创建微博
 * @param: {Object} param0 创建微博所需要的数据{userId, content, image}
 */
async function create({ userId, content, image }) {
    // service
    try {
        // 创建微博
        const blog = await createBlog({
            userId,
            content: xss(content),
            image,
        })
        return new SuccessModel(blog)
    } catch (ex) {
        console.error(ex.message, ex.stack)
        return new ErrorModel(createBlogFailInfo)
    }
}

module.exports = {
    create,
}
